import logging
from functools import wraps
from flask_login import current_user

logger = logging.getLogger()
logger.setLevel(logging.WARN)
formatter = logging.Formatter('%(asctime)s [%(process)d] [%(levelname)s] %(message)s',
                              datefmt='[%Y-%m-%d %H:%M:%S +000]')
logfile = '/usr/local/dataportal/flask_dataportal.log'
logfile = 'test.log'
fh = logging.FileHandler(logfile)
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.warn('ready......')
logger.setLevel(logging.CRITICAL)

def logger(message):
    def _deco1(func):
        @wraps(func)
        def __deco1():
            logger('-------- user:' + current_user.get_name() + '(' + current_user.get_cn() + ') visit: ' + message)
            return func()

        return __deco1

    return _deco1
